package mscadm

import (
	"github.com/gin-gonic/gin"
	"github.com/gogap/logs"
	"yundian/internel/app/helper/resphelper/placeresp"
	"yundian/internel/app/models/placemodel"

	"yundian/internel/app/dao"
	"yundian/internel/app/helper"
	"yundian/internel/app/helper/request"
	"yundian/internel/app/logic"
	"yundian/internel/app/models/bulletin"
	"yundian/internel/app/models/comment"
	"yundian/internel/app/models/coupon"
	"yundian/internel/app/models/room"
	"yundian/internel/pkg/dingo"
	. "yundian/internel/pkg/dingo/result"
)

// HandleGetStewardServiceAutomateReplenishList 补货服务数据列表
func HandleGetStewardServiceAutomateReplenishList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.NotificationListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)
	param.ParentId, _ = helper.GetParentIdFromCtx(ctx)

	data := dao.NewNotificationDaoDao().GetStewardServiceAutomateReplenishList(param)

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleGetStewardServiceAutomateReplenishDataList 补货服务数据列表
func HandleGetStewardServiceAutomateReplenishDataList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.NotificationListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)
	param.ParentId, _ = helper.GetParentIdFromCtx(ctx)

	data := dao.NewNotificationDaoDao().GetStewardServiceAutomateReplenishDataList(param)

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleDeletePlacesServiceMaterials 服务物品配置
func HandleDeletePlacesServiceMaterials(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &placemodel.PlacesServiceMaterialsDb{}
	param := &request.DbPlacesServiceMaterialsListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.DB = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewNotificationDaoDao().DeletePlacesServiceMaterials(param); data.Err != nil {
		Response(ctx)(data.Err.Error(), CodeInvalidParam, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleInsertPlacesServiceMaterials 服务物品配置
func HandleInsertPlacesServiceMaterials(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &placemodel.PlacesServiceMaterialsDb{}
	param := &request.DbPlacesServiceMaterialsListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.DB = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewNotificationDaoDao().InsertPlacesServiceMaterials(param); data.Err != nil {
		Response(ctx)(data.Err.Error(), CodeInvalidParam, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleUpdatePlacesServiceMaterials 服务物品配置
func HandleUpdatePlacesServiceMaterials(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &placemodel.PlacesServiceMaterialsDb{}
	param := &request.DbPlacesServiceMaterialsListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.DB = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewNotificationDaoDao().UpdatePlacesServiceMaterials(param); data.Err != nil {
		Response(ctx)(data.Err.Error(), CodeInvalidParam, false)(OK)
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleGetPlacesServiceMaterialsList 服务物品配置-列表
func HandleGetPlacesServiceMaterialsList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.PlacesServiceMaterialsListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	data := dao.NewNotificationDaoDao().GetAdminPlacesServiceMaterialsList(param)

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleGrantOrderCouponDevice 优惠券-设备预发放
func HandleGrantOrderCouponDevice(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.GrantOrderCouponReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewCouponDao().GrantOrderCouponDevice(param); data.Err != nil {
		Response(ctx)("", CodeInvalidParam, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleGrantOrderCoupon 优惠券-发放
func HandleGrantOrderCoupon(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.GrantOrderCouponReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if param.IsAdmin != helper.TypeNumIsAdminOperator && param.IsAll == 1 {
		Response(ctx)("", CodeInvalidParam, false)(OK)
		return
	}

	if data := dao.NewCouponDao().GrantOrderCoupon(param); data.Err != nil {
		Response(ctx)("", CodeInvalidParam, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleGetOrderCouponRecordList 优惠券记录
func HandleGetOrderCouponRecordList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.GetOrderCouponRecordListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	data := dao.NewCouponDao().GetOrderCouponRecord(param)
	list := data.Unwrap().([]*request.GetOrderCouponRecordListRes)

	var placeIds []int
	m := map[int]bool{}
	for _, item := range list {
		if item.PlaceId > 0 && !m[item.PlaceId] {
			m[item.PlaceId] = true
			placeIds = append(placeIds, item.PlaceId)
		}
	}

	placeList := dao.NewPlaceDao().GetPlaceByPlaceIds(placeIds).Unwrap().([]*placeresp.GetPlaceIdWithHotelId)
	for _, item := range list {
		for _, placeInfo := range placeList {
			if item.PlaceId == placeInfo.Id {
				item.PlaceName = placeInfo.PlaceName
				break
			}
		}
	}

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleDeleteOrderCoupon 优惠券
func HandleDeleteOrderCoupon(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &coupon.OrderCouponDb{}
	param := &request.DbOrderCouponReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.DB = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewCouponDao().DeleteOrderCoupon(param); data.Err != nil {
		Response(ctx)("", CodeInvalidParam, false)(OK)
	} else if data.Unwrap().(int64) > 0 {
		Response(ctx)("优惠券已发放", CodeInvalidParam, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleUpdateOrderCoupon 优惠券
func HandleUpdateOrderCoupon(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &coupon.OrderCouponDb{}
	param := &request.DbOrderCouponReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.DB = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewCouponDao().UpdateOrderCoupon(param); data.Err != nil {
		Response(ctx)("", CodeInvalidParam, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleInsertOrderCoupon 优惠券
func HandleInsertOrderCoupon(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &coupon.OrderCouponDb{}
	param := &request.DbOrderCouponReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.DB = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewCouponDao().InsertOrderCoupon(param); data.Err != nil {
		Response(ctx)("", CodeInvalidParam, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleGetOrderCouponList 优惠券-列表
func HandleGetOrderCouponList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.GetCouponListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	data := dao.NewCouponDao().GetOrderCoupon(param)

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleSetPlaceReportsStatus 门店投诉建议
func HandleSetPlaceReportsStatus(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.GetPlaceReportsListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	data := dao.NewReportDao().SetAdminPlaceReportStatus(param)
	Response(ctx)("", CodeSuccess, data.Unwrap())(OK)
}

// HandleGetPlaceReportsDetails 门店投诉建议
func HandleGetPlaceReportsDetails(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.GetPlaceReportsListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	data := dao.NewReportDao().GetAdminPlaceReportDetails(param)
	Response(ctx)("", CodeSuccess, data.Unwrap())(OK)
}

// HandleGetPlaceReportsList 门店投诉建议
func HandleGetPlaceReportsList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.GetPlaceReportsListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	data := dao.NewReportDao().GetAdminPlaceReportList(param)

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleSetStewardPlaceBulletinClose 公告
func HandleSetStewardPlaceBulletinClose(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &bulletin.UpdateDb{}
	param := &request.DbBulletinReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.Db = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewBulletinDao().SetStewardPlaceBulletinClose(param); data.Err != nil {
		Response(ctx)("", CodeInternalServerError, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleSetStewardBulletinStatus 公告审核
func HandleSetStewardBulletinStatus(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &bulletin.UpdateDb{}
	param := &request.DbBulletinReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.Db = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)
	param.ParentId, _ = helper.GetParentIdFromCtx(ctx)

	if helper.IsAdminAndStaff(param.IsAdmin, param.ParentId) {
		param.IsAdmin = helper.TypeNumIsAdminOperator
	}

	if data := dao.NewBulletinDao().SetAdminBulletinStatus(param); data.Err != nil {
		Response(ctx)("", CodeInternalServerError, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleDeleteStewardBulletin 公告
func HandleDeleteStewardBulletin(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &bulletin.UpdateDb{}
	param := &request.DbBulletinReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.Db = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewBulletinDao().DeleteAdminBulletinList(param); data.Err != nil {
		Response(ctx)("", CodeInternalServerError, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleUpdateStewardBulletin 公告
func HandleUpdateStewardBulletin(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &bulletin.UpdateDb{}
	param := &request.DbBulletinReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.Db = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewBulletinDao().UpdateAdminBulletinList(param); data.Err != nil {
		Response(ctx)("", CodeInternalServerError, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleInsertStewardBulletin 公告
func HandleInsertStewardBulletin(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	data := &bulletin.UpdateDb{}
	param := &request.DbBulletinReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(data)).Unwrap()
	param.Db = data
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if data := dao.NewBulletinDao().InsertAdminBulletinList(param); data.Err != nil {
		Response(ctx)("", CodeInternalServerError, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleGetStewardBulletinList 查询公告列表
func HandleGetStewardBulletinList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.BulletinListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)
	param.ParentId, _ = helper.GetParentIdFromCtx(ctx)

	if helper.IsAdminAndStaff(param.IsAdmin, param.ParentId) {
		param.IsAdmin = helper.TypeNumIsAdminOperator
	}

	data := dao.NewBulletinDao().GetAdminBulletinList(param)

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleStewardSetCommentStatus 好评有礼审核
func HandleStewardSetCommentStatus(ctx *gin.Context) {
	param := &comment.ThirdComment{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	if data := dao.NewCommentDao().SetCommentStatus(param); data.Err != nil {
		Response(ctx)("", CodeError, false)(OK)
		return
	}
	if param.Status == 2 { // 审核通过 通知
		logs.Info("审核成功", param.Id)
		dingo.Task(logic.NewShWxNotificationsLogic().WeChatGroupRobotNotificationsByHotelGoodsCommit, func() {}, param.Id)
	}
	Response(ctx)("", CodeSuccess, true)(OK)
}

// HandleStewardAddRoomCoupon 房间优惠
func HandleStewardAddRoomCoupon(ctx *gin.Context) {
	param := &request.StewardAddRoomCouponReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()

	//param.Amount = 200
	data := dao.NewCouponDao().StewardAddRoomCoupon(param)
	Response(ctx)("", CodeSuccess, map[string]interface{}{"amount": data.Unwrap()})(OK)
}

// HandleStewardGetServiceConfig 获取服务设置
func HandleStewardGetServiceConfig(ctx *gin.Context) {
	param := &request.SetStewardPlaceSetServiceConfigReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()

	data := dao.NewNotificationDaoDao().GetPlaceServiceConfig(param)
	Response(ctx)("", CodeSuccess, data.Unwrap())(OK)
}

// HandleStewardSetServiceConfig 服务设置
func HandleStewardSetServiceConfig(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.SetStewardPlaceSetServiceConfigReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()

	if data := dao.NewNotificationDaoDao().SetPlaceServiceConfig(param); data.Err != nil {
		Response(ctx)("", CodeSuccess, false)(OK)
		return
	}
	Response(ctx)("", CodeSuccess, userId)(OK)
}

// HandleStewardSetStatus 服务状态设置
func HandleStewardSetStatus(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.StewardSetDataReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()

	if data := dao.NewNotificationDaoDao().SetNotificationServiceData(param); data.Err != nil {
		Response(ctx)("", CodeSuccess, false)(OK)
		return
	}
	Response(ctx)("", CodeSuccess, userId)(OK)
}

// HandleGetStewardServiceInfo 查询服务列表
func HandleGetStewardServiceInfo(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.NotificationListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	data := dao.NewNotificationDaoDao().GetNotificationServiceInfo(param)

	Response(ctx)("", CodeSuccess, data.Unwrap())(OK)
}

// HandleGetStewardServiceStatusInfo 查询服务状态数量
func HandleGetStewardServiceStatusInfo(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.NotificationListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	data := dao.NewNotificationDaoDao().GetNotificationServiceStatusInfo(param)
	Response(ctx)("", CodeSuccess, data.Unwrap())(OK)
}

// HandleGetStewardServiceList 查询服务列表
func HandleGetStewardServiceList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.NotificationListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)
	param.ParentId, _ = helper.GetParentIdFromCtx(ctx)

	data := dao.NewNotificationDaoDao().GetNotificationServiceList(param)

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleGetStewardServiceRoomsList 查询服务列表-客房续住
func HandleGetStewardServiceRoomsList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.NotificationListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)
	param.ParentId, _ = helper.GetParentIdFromCtx(ctx)
	param.Type = 6

	data := dao.NewNotificationDaoDao().GetNotificationServiceRoomList(param)
	list := data.Unwrap().([]*request.NotificationRoomListRes)

	var notificationIds []int
	for _, item := range list {
		notificationIds = append(notificationIds, item.Id)
	}

	if len(notificationIds) > 0 {
		orderList := dao.NewRoomDaoDao().GetAdminRoomOrdersByNotificationIds(notificationIds).Unwrap().([]*room.Order)
		for _, item := range list {
			for _, item1 := range orderList {
				if item.Id == item1.NotificationId {
					item.DayLen = item1.DayLen
					item.OrderStatus = item1.Status
					item.PayType = item1.PayType
					item.AllAmount = int64(item1.Amount)
					item.TradeNo = item1.TradeNo
					break
				}
			}
		}
	}

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleGetStewardServiceGoodsList 查询服务列表-客房超市
func HandleGetStewardServiceGoodsList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.NotificationListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)
	param.ParentId, _ = helper.GetParentIdFromCtx(ctx)
	param.Type = 11

	data := dao.NewNotificationDaoDao().GetNotificationServiceGoodsList(param)
	list := data.Unwrap().([]*request.NotificationGoodsListRes)

	var notificationIds []int
	for _, item := range list {
		notificationIds = append(notificationIds, item.Id)
	}

	if len(notificationIds) > 0 {
		orderList := dao.NewGoodsDao().GetGoodsOrdersByNotificationIds(notificationIds).Unwrap().([]*request.GoodsListOrderRes)
		for _, item := range list {
			for _, item1 := range orderList {
				if item.Id == item1.NotificationId {
					item.GoodsNum = item1.GoodsNum
					item.AllAmount = item1.AllAmount
					item.TradeNo = item1.TradeNo
					item.OrderStatus = item1.Status
					break
				}
			}
		}
	}

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleGetStewardServiceCommentList 查询服务列表-好评有礼
func HandleGetStewardServiceCommentList(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.NotificationListReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)
	param.ParentId, _ = helper.GetParentIdFromCtx(ctx)
	param.Type = 9

	var orderIds []int
	data := dao.NewNotificationDaoDao().GetNotificationServiceCommentList(param)
	for _, item := range data.Unwrap().([]*request.NotificationCommentListRes) {
		if item.GoodsType == helper.TypeNumGoodsTypeCash && item.Status == helper.TypeNumNotificationStatusFinish {
			orderIds = append(orderIds, item.GoodsOrderId)
		}
	}
	redPacket := dao.NewNotificationDaoDao().GetCommentRedPacketReceiveListByOrderIds(orderIds)
	for _, item := range data.Unwrap().([]*request.NotificationCommentListRes) {
		for _, rItem := range redPacket.Unwrap().([]*comment.SendRedPacketRecord) {
			if item.GoodsOrderId == rItem.OrderId {
				item.GrantStatus = rItem.Status
				break
			}
		}
	}

	Response(ctx)("", CodeSuccess, ResponseList{
		PageNo:     param.PageNo,
		PageSize:   param.PageSize,
		TotalCount: data.Val().(int64),
		TotalPage:  (data.Val().(int64) + int64(param.PageSize) - 1) / int64(param.PageSize),
		Data:       data.Unwrap(),
	})(OK)
}

// HandleGrantServiceCommentAward 好评有礼-发放奖励
func HandleGrantServiceCommentAward(ctx *gin.Context) {
	userId, err := helper.GetUserIdFromCtx(ctx)
	dingo.ErrorIf(err).Unwrap()

	param := &request.GrantServiceCommentAwardReq{}
	dingo.ErrorIf(ctx.ShouldBindJSON(param)).Unwrap()
	param.LoginUserId = userId
	param.IsAdmin, _ = helper.GetIsAdminFromCtx(ctx)

	if param.IsAdmin != helper.TypeNumIsAdminOperator {
		Response(ctx)("", CodeInvalidParam, false)(OK)
		return
	}

	if dao.NewNotificationDaoDao().GrantServiceCommentAward(param).Err != nil {
		Response(ctx)("", CodeInternalServerError, false)(OK)
		return
	}

	Response(ctx)("", CodeSuccess, true)(OK)
}
